package trees;

import java.util.ArrayDeque;
import java.util.Queue;

public class FindBottomLeftValue {
    public int findBottomLeftValue(TreeNode root) {
        if (root == null) {
            return 0;
        }

        Queue<TreeNode> queue = new ArrayDeque<>();
        queue.offer(root);
        TreeNode temp = new TreeNode(-1);
        while (!queue.isEmpty()) {
            temp = queue.poll();
            if (temp != null) {
                if (temp.right != null) {
                    queue.offer(temp.right);
                }

                if (temp.left != null) {
                    queue.offer(temp.left);
                }
            }
        }

        return temp == null ? 0 : temp.val;
    }
}
